#ifndef __H_TTC_CLIENT_UNIT_H__
#define __H_TTC_CLIENT_UNIT_H__

#include <global.h>
#include <noncopyable.h>
#include <client_unit.h>

class CPollerUnit;
class CTimerList;

HTTP_SVR_NS_BEGIN

class THttpStateInfo;
class CClientUnit;
class CHelperUnit;
class CListener;

typedef struct _FdInfo
{
    CClientUnit*    pClientUnit;
    CHelperUnit*    pHelperUnit;
    THttpStateInfo* pHttpInfo;
}FdInfo;

class CDecoderUnit : private noncopyable
{
    friend class CListener;
public:
	CDecoderUnit (CListener* owner, THttpStateInfo* httpinfo);
	~CDecoderUnit (void);

	int listener_input (void);
    int web_input (void);
    int cgi_input (void);

    int web_output (void);
    int cgi_output (void);

    int web_hangup (void);
    
    int cgi_hangup (void);

    int web_timer (void);
    int cgi_timer (void);

    void complete (void);


    void helper_complete (void);

    inline CTimerList* get_web_timer (void) const { return _webTimer; }
    inline void set_web_timer (CTimerList* timerlist) { _webTimer = timerlist; }

    inline CTimerList* get_helper_timer (void) const { return _helperTimer; }
    inline void set_helper_timer (CTimerList* timerlist) { _helperTimer = timerlist; }
    
    inline CPollerUnit* pollerunit (void) const { return _pollerUnit; }
    inline void pollerunit (CPollerUnit* pollerunit) { _pollerUnit = pollerunit; }    

	inline CClientUnit* get_web_unit (void) const {return _webUnit;}
    
    int add_rsp_buffer(char* buffer, int len, int type = RSP_NORMAL_ITEM);

    inline void set_qvia_flag(bool flag)
    {
        _bCheckQvia = flag;
    }

	int get_helper_rspBuff(char ** rspBuff, int &rspLen);

	void free_helper_buf();
	
private:
    CPollerUnit*    _pollerUnit;
    CTimerList*     _webTimer;
    CTimerList*     _helperTimer;

    THttpStateInfo* _httpInfo;
    CClientUnit*    _webUnit;
    CHelperUnit*    _helperUnit;

    CListener*      _listener;

    bool            _bCheckQvia;
};

HTTP_SVR_NS_END

#endif
